import 'package:flutter/material.dart';
import 'package:flutter_09_game/base/widget/base_get_builder.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/generated/assets.dart';
import 'package:flutter_09_game/generated/locales.g.dart';
import 'package:flutter_09_game/user/app_user_manager.dart';
import 'package:flutter_09_game/user/model/app_user_info_model.dart';
import 'package:flutter_09_game/utils/log/utils_log.dart';
import 'package:flutter_09_game/widgets/appbar/common_app_bar.dart';
import 'package:flutter_09_game/widgets/button/debounce_gesture_detector.dart';
import 'package:flutter_09_game/widgets/image/auto_image.dart';
import 'package:flutter_09_game/widgets/image/image_view.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'profile_edit_logic.dart';

class ProfileEditPage extends StatelessWidget {
  ProfileEditPage({super.key});

  final ProfileEditLogic logic = Get.put(ProfileEditLogic());

  @override
  Widget build(BuildContext context) {
    return BaseGetBuilder<ProfileEditLogic>(
      appBar: CommonAppBar(title: LocaleKeys.editProfile.tr),
      builder: (_) {
        return Obx(() {
          AppUserInfoModelUser? user = AppUserManager().user.value;
          return Column(
            // crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [

            const  Row(),
              16.verticalSpaceFromWidth,


             GestureDetector(
               onTap: () {
                 logic.showAvatarSheet();
               },
               child:  SizedBox(
                 width: 100.w,
                 height: 100.w,
                 child: Stack(
                   children: [
                     ImageView(
                       imageUrl: user?.avatar,
                       radius: 50.w,
                     ),
                     Positioned(
                         bottom: 0,
                         right: 0,
                         child: AutoImage(
                           Assets.mineEditAvatar,
                           width: 32.w,
                         ))
                   ],
                 ),
               ),
             ),
              16.verticalSpaceFromWidth,
              _buildUserNameEditItem(user),
            ],
          );
        });
      },
    );
  }

  /// 构建用户名编辑项
  Widget _buildUserNameEditItem(AppUserInfoModelUser? user) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      child: DebounceGestureDetector(
        onTap: () => logic.goToEditUserName(),
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 24.w),
          decoration: BoxDecoration(
            color: AppColor.navBgColor,
            borderRadius: BorderRadius.circular(12.w),
          ),
          child: Row(
            children: [
              // 左侧标签
              Text(
                LocaleKeys.username.tr,
                style: TextStyle(
                  fontSize: 14.sp,
                  fontWeight: FontWeight.w400,
                  color: AppColor.textPrimary.withOpacity(0.7),
                ),
              ),
              16.horizontalSpace,
              // 中间用户名
              Expanded(
                child: Text(
                  user?.username ?? '',
                  textAlign: TextAlign.end,
                  style: TextStyle(
                    fontSize: 14.sp,
                    fontWeight: FontWeight.w600,
                    color: AppColor.textPrimary.withOpacity(0.94),
                  ),
                ),
              ),
              // 右侧箭头
              AutoImage(
                Assets.mineRigthtRight,
                width: 24.w,
                height: 24.w,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
